home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / timeplt.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  128 lines

  1. /***************************************************************************
  2.  
  3.     This code is used by the following module:
  4.  
  5.     timeplt.c
  6.     pooyan.c
  7.     locomotn.c
  8.     tutankhm.c
  9.     rocnrope.c
  10.  
  11. ***************************************************************************/
  12.  
  13. #include "driver.h"
  14.  
  15. static READ_HANDLER( timeplt_portB_r );
  16. static WRITE_HANDLER( timeplt_filter_w );
  17.  
  18. struct MemoryReadAddress timeplt_sound_readmem[] =
  19. {
  20.     { 0x0000, 0x1fff, MRA_ROM },
  21.     { 0x2000, 0x23ff, MRA_RAM },
  22.     { 0x3000, 0x33ff, MRA_RAM },
  23.     { 0x4000, 0x4000, AY8910_read_port_0_r },
  24.     { 0x6000, 0x6000, AY8910_read_port_1_r },
  25.     { -1 }    /* end of table */
  26. };
  27.  
  28. struct MemoryWriteAddress timeplt_sound_writemem[] =
  29. {
  30.     { 0x0000, 0x1fff, MWA_ROM },
  31.     { 0x2000, 0x23ff, MWA_RAM },
  32.     { 0x3000, 0x33ff, MWA_RAM },
  33.     { 0x4000, 0x4000, AY8910_write_port_0_w },
  34.     { 0x5000, 0x5000, AY8910_control_port_0_w },
  35.     { 0x6000, 0x6000, AY8910_write_port_1_w },
  36.     { 0x7000, 0x7000, AY8910_control_port_1_w },
  37.     { 0x8000, 0x8fff, timeplt_filter_w },
  38.     { -1 }    /* end of table */
  39. };
  40.  
  41.  
  42. struct AY8910interface timeplt_ay8910_interface =
  43. {
  44.     2,                /* 2 chips */
  45.     14318180/8,        /* 1.789772727 MHz */
  46.     { MIXERG(30,MIXER_GAIN_2x,MIXER_PAN_CENTER), MIXERG(30,MIXER_GAIN_2x,MIXER_PAN_CENTER) },
  47.     { soundlatch_r },
  48.     { timeplt_portB_r },
  49.     { 0 },
  50.     { 0 }
  51. };
  52.  
  53.  
  54. /* The timer clock which feeds the upper 4 bits of                        */
  55. /* AY-3-8910 port A is based on the same clock                            */
  56. /* feeding the sound CPU Z80.  It is a divide by                          */
  57. /* 5120, formed by a standard divide by 512,                            */
  58. /* followed by a divide by 10 using a 4 bit                               */
  59. /* bi-quinary count sequence. (See LS90 data sheet                        */
  60. /* for an example).                                                       */
  61. /*                                                                        */
  62. /* Bit 4 comes from the output of the divide by 1024                      */
  63. /*       0, 1, 0, 1, 0, 1, 0, 1, 0, 1                                    */
  64. /* Bit 5 comes from the QC output of the LS90 producing a sequence of    */
  65. /*          0, 0, 1, 1, 0, 0, 1, 1, 1, 0                                    */
  66. /* Bit 6 comes from the QD output of the LS90 producing a sequence of    */
  67. /*         0, 0, 0, 0, 1, 0, 0, 0, 0, 1                                    */
  68. /* Bit 7 comes from the QA output of the LS90 producing a sequence of    */
  69. /*         0, 0, 0, 0, 0, 1, 1, 1, 1, 1                                     */
  70.  
  71. static int timeplt_timer[10] =
  72. {
  73.     0x00, 0x10, 0x20, 0x30, 0x40, 0x90, 0xa0, 0xb0, 0xa0, 0xd0
  74. };
  75.  
  76. static READ_HANDLER( timeplt_portB_r )
  77. {
  78.     /* need to protect from totalcycles overflow */
  79.     static int last_totalcycles = 0;
  80.  
  81.     /* number of Z80 clock cycles to count */
  82.     static int clock;
  83.  
  84.     int current_totalcycles;
  85.  
  86.     current_totalcycles = cpu_gettotalcycles();
  87.     clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
  88.  
  89.     last_totalcycles = current_totalcycles;
  90.  
  91.     return timeplt_timer[clock/512];
  92. }
  93.  
  94.  
  95. static void filter_w(int chip, int channel, int data)
  96. {
  97.     int C = 0;
  98.  
  99.     if (data & 1) C += 220000;    /* 220000pF = 0.220uF */
  100.     if (data & 2) C +=  47000;    /*  47000pF = 0.047uF */
  101.     set_RC_filter(3*chip + channel,1000,5100,0,C);
  102. }
  103.  
  104. static WRITE_HANDLER( timeplt_filter_w )
  105. {
  106.     filter_w(0, 0, (offset >>  6) & 3);
  107.     filter_w(0, 1, (offset >>  8) & 3);
  108.     filter_w(0, 2, (offset >> 10) & 3);
  109.     filter_w(1, 0, (offset >>  0) & 3);
  110.     filter_w(1, 1, (offset >>  2) & 3);
  111.     filter_w(1, 2, (offset >>  4) & 3);
  112. }
  113.  
  114.  
  115. WRITE_HANDLER( timeplt_sh_irqtrigger_w )
  116. {
  117.     static int last;
  118.  
  119.     if (last == 0 && data)
  120.     {
  121.         /* setting bit 0 low then high triggers IRQ on the sound CPU */
  122.         cpu_cause_interrupt(1,0xff);
  123.     }
  124.  
  125.     last = data;
  126. }
  127.  
  128.